package com.property.manage.controller.equipment;

import com.guardchina.framework.mybatis.model.CustomPage;
import com.property.manage.model.equipment.EquipmentVo;
import com.property.manage.model.equipment.MaintenanceVo;
import com.property.manage.service.equipment.EquipmentService;
import com.property.manage.service.equipment.MaintenanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/7/15
 */
@Api(tags = "设备管理记录")
@RestController
@RequestMapping("/maintenance")
@AllArgsConstructor
@Validated
public class MaintenanceController {
    @Autowired
    private MaintenanceService maintenanceService;


    @ApiOperation("设备保养和维修记录列表")
    @GetMapping("/page")
    public CustomPage<MaintenanceVo> userPage(@ApiParam("当前页码") @RequestParam("pageNo") @NotNull(message = "请输入当前页码") Long pageNo,
                                              @ApiParam("每页条数") @RequestParam("pageSize") @NotNull(message = "请输入每页条数") Long pageSize,
                                              @ApiParam("小区id") @RequestParam(value = "quarterId", required = false) Integer quarterId,
                                              @ApiParam("设备名称") @RequestParam(value = "name", required = false) String name){
        return maintenanceService.page(pageNo,pageSize,quarterId,name);
    }

    @ApiOperation("添加")
    @PostMapping("/add")
    public void add(@ApiParam("小区id")@RequestParam(value = "villageId")@NotNull(message = "小区id不能为空") Integer villageId,
                    @ApiParam("设备名称")@RequestParam(value = "name")@NotBlank(message = "设备名称") String name,
                    @ApiParam("设备编号") @RequestParam(value = "number")@NotBlank(message = "设备编号不能为空") String number,
                    @ApiParam("维修和保养的时间")@RequestParam(value = "maintenanceTime")@NotNull(message = "维修和保养的时间不能为空") LocalDate maintenanceTime,
                    @ApiParam("下次保养或维修时间")@RequestParam(value = "nextTime",required = false) LocalDate nextTime,
                    @ApiParam("维修费用")@RequestParam(value = "money",required = false)BigDecimal money,
                    @ApiParam("维修与保养人员")@RequestParam(value = "personnel")@NotBlank(message = "维修与保养人员不能为空") String personnel,
                    @ApiParam("联系电话")@RequestParam(value = "phone")@NotBlank(message = "联系电话不能为空") String phone


    ){
       maintenanceService.add(name,number,maintenanceTime,villageId,nextTime,money,personnel,phone);
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public void update(@RequestParam(value = "id")@NotNull(message = "id不能为空") Integer id,
                       @ApiParam("小区id")@RequestParam(value = "villageId")@NotNull(message = "小区id不能为空") Integer villageId,
                       @ApiParam("设备名称")@RequestParam(value = "name")@NotBlank(message = "设备名称") String name,
                       @ApiParam("设备编号") @RequestParam(value = "number")@NotBlank(message = "设备编号不能为空") String number,
                       @ApiParam("维修和保养的时间")@RequestParam(value = "maintenanceTime")@NotNull(message = "维修和保养的时间不能为空") LocalDate maintenanceTime,
                       @ApiParam("下次保养或维修时间")@RequestParam(value = "nextTime",required = false) LocalDate nextTime,
                       @ApiParam("维修费用")@RequestParam(value = "money",required = false)BigDecimal money,
                       @ApiParam("维修与保养人员")@RequestParam(value = "personnel")@NotBlank(message = "维修与保养人员不能为空") String personnel,
                       @ApiParam("联系电话")@RequestParam(value = "phone")@NotBlank(message = "联系电话不能为空") String phone
    ){
      maintenanceService.update(id,name,number,maintenanceTime,villageId,nextTime,money,personnel,phone);
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public void delete(@ApiParam("id") @RequestParam("id") @NotNull(message = "id为空") Integer id){
        maintenanceService.delete(id);
    }


}
